
package cn.org.seventh.web.common;

import java.util.Map;

import org.springframework.mail.SimpleMailMessage;

/**
 * @author <a href="mailto:ji.li@symbio-group.com">Andy</a>
 * @since Dec 20, 2007 4:00:52 PM
 */
public class MockMailService extends MailService {

    public void send(SimpleMailMessage msg) {
        StringBuffer mail = new StringBuffer();
        mail.append(getMailHeader(msg) + "\n");
        mail.append(msg.getText());
        log.info(mail.toString());
    }

    public void send(SimpleMailMessage msg, String templateName, Map model) {
        StringBuffer mail = new StringBuffer();
        mail.append(getMailHeader(msg) + "\n");
        mail.append(generateEmailContent(templateName, model));
        log.info(mail.toString());
    }

    protected String getMailHeader(SimpleMailMessage msg) {
        StringBuffer header = new StringBuffer();
        header.append("To: ");
        String temp[] = msg.getTo();
        for (int i = 0; i < temp.length; i++) {
            String to = temp[i];
            header.append(to).append(";");
        }
        header.append("\nFrom: " + msg.getFrom());
        header.append("\nSubject: " + msg.getSubject());
        return header.toString();
    }
}
